import random


class Player:
    HUMAN = 1
    MACHINE = 2

    def __init__(self, name, cardBox, playerType):
        self.name = name
        self.cardBox = cardBox
        self.playerType = playerType

    def isEmptyByCardBox(self):
        return self.cardBox.isEmpty()

    '''
    def showSkillInfo(self, card):
        print('%s的技能是：' % card[0], end='')
        for i in range(len(card[2])):
            print('[%d-%s/%s]' % (i + 1, card[2][i][0], card[2][i][1]), end='')
        print()
    '''

    def attach(self, enemy):
        if self.isEmptyByCardBox():
            return

        roleTitle = '[%s攻击]' % self.name
        print(roleTitle)
        if self.playerType == self.HUMAN:
            gongji = int(input('请选择%s攻击卡牌：' % self.name))
            #self.showSkillInfo(gongjifang[gongji - 1])
            #jineng = int(input('请选择攻击技能：'))
            beigongji = int(input('请选择%s被攻击卡牌：' % enemy.name))
        else:
            gongji = random.randint(1, self.cardBox.cardsCount())
            beigongji = random.randint(1, enemy.cardBox.cardsCount())

        enemy.cardBox.cards[beigongji - 1].hp -= 3

        if enemy.cardBox.cards[beigongji - 1].hp <= 0:
            print('[%d-%s]攻击了[%d-%s]，[%d-%s]弃牌' % (
                gongji, self.cardBox.cards[gongji - 1].name,
                beigongji, enemy.cardBox.cards[beigongji - 1].name,
                beigongji, enemy.cardBox.cards[beigongji - 1].name))
            enemy.cardBox.cards.pop(beigongji - 1)
        else:
            print('[%d-%s]攻击了[%d-%s]，[%d-%s]生命值为%d' % (
                gongji, self.cardBox.cards[gongji - 1].name,
                beigongji, enemy.cardBox.cards[beigongji - 1].name,
                beigongji, enemy.cardBox.cards[beigongji - 1].name,
                enemy.cardBox.cards[beigongji - 1].hp))
